<?php

declare(strict_types=1);

namespace App\Controller\act;

use App\Controller\AbstractController;
use App\Service\act\ActService;
use App\Service\BaseService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;

#[Controller(prefix: "act")]
class ActController extends AbstractController
{
    /**
     * 充值转盘活动触发进度
     * @return null
     */
    #[GetMapping(path: 'getRWTriggerProgress')]
    public function getRechargeWheelTriggerProgress(){
        // 参数校验
        $params = $this->request->getQueryParams();
        $validator = $this->validatorFactory->make($params,
            [
                'uid' => 'required'
            ]
        );
        if ($validator->fails()) {
            return $this->ReturnJson->failFul(201, null, 1, $validator->errors()->first());
        }
        try {
            $res = ActService::getRechargeWheelTriggerProgress($params['uid']);
            return $this->ReturnJson->successFul(200, $res);
        } catch (\Throwable $e) {
            BaseService::writeExceptionMsg($e, __CLASS__.'.'.__FUNCTION__);
            return $this->ReturnJson->failFul($e->getCode());
        }
    }

    /**
     * 获取充值转盘抽奖记录
     * @return null
     */
    #[GetMapping(path: 'getRWDrawLog')]
    public function getRechargeWheelDrawLog(){
        // 参数校验
        $params = $this->request->getQueryParams();
        $validator = $this->validatorFactory->make($params,
            [
                'uid' => 'required'
            ]
        );
        if ($validator->fails()) {
            return $this->ReturnJson->failFul(201, null, 1, $validator->errors()->first());
        }
        try {
            $params['act_ids'] = array_values(ActService::$rechargeWheelActIds); // 充值转盘活动id
            $res = ActService::getDrawLog($params);
            return $this->ReturnJson->successFul(200, $res);
        } catch (\Throwable $e) {
            BaseService::writeExceptionMsg($e, __CLASS__.'.'.__FUNCTION__);
            return $this->ReturnJson->failFul($e->getCode());
        }
    }

    /**
     * 获取充值转盘中奖记录
     * @return null
     */
    #[GetMapping(path: 'getRWWinLog')]
    public function getRechargeWheelWinLog(){
        try {
            $res = ActService::getRechargeWheelBigWinDrawLog();
            return $this->ReturnJson->successFul(200, $res);
        } catch (\Throwable $e) {
            BaseService::writeExceptionMsg($e, __CLASS__.'.'.__FUNCTION__);
            return $this->ReturnJson->failFul($e->getCode());
        }
    }
}
